# -*- encoding: utf-8 -*-
"""
    package.module
    ~~~~~~~~~~~~~~

    project config

    :copyright: (c)  2018/5/22 by zwhset.
    :license: OPS, see LICENSE_FILE for more details.
"""

import os

basedir = os.path.abspath(os.path.dirname(__file__))  # 设置基础目录
LOCONFIG="a"

class Config(object):
    '''配置基础类'''
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'TxuvWdN[PYOB2V0yMGn5q4Fk'
    SQLALCHEMY_TRACK_MODIFICATIONS = True  # 取消这个报警信息

    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    '''开发类'''
    LOCONFIG="./log/logger.conf"
    DEBUG = True
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = '6379'
    REDIS_URL = "redis://127.0.0.1:6379"
    REDIS_PASSWORD = None
    REDIS_DB = 0
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://username:password@host:port/db?charset=utf8mb4'
    FTP_HOST = dict(
        dev="dev.kftp.qianbao-inc.com",
        qa="qa.kftp.qianbao-inc.com"
    )
    PROJECT_API = 'http://devops.qianbao-inc.com'
    NCONF_API = 'http://test-nconf.qianbao-inc.com'


class ProductionConfig(Config):
    DEBUG = False
    # REDIS_HOST = '10.64.132.30'
    REDIS_HOST = '10.19.34.203'
    # REDIS_PORT = '6379'
    REDIS_PORT = '7002'
    REDIS_URL = "redis://10.19.34.203:7002"
    REDIS_PASSWORD = None
    # REDIS_DB = 0
    REDIS_DB = 2
    FTP_HOST = dict(
        pre="kftp.qianbao-inc.com",
        pro="kftp.qianbao-inc.com",
        qa="qa.kftp.qianbao-inc.com",
        dev="dev.kftp.qianbao-inc.com",
    )
    PROJECT_API = 'http://devops.qianbao-inc.com'
    NCONF_API = 'http://nconf.qianbao-inc.com'
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://username:password@host:port/db?charset=utf8mb4'


# config = {
#     'development': DevelopmentConfig,
#     'production': ProductionConfig,
#
#     'default': ProductionConfig,
# }

# 默认走开发环境
# ENV = os.getenv('FLASK_CONFIG') or 'default'
# configure = config.get(ENV)


# 兼容 container 注入APPENV
config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'dev': DevelopmentConfig,
    'qa': DevelopmentConfig,
    'pre': ProductionConfig,
    'pro': ProductionConfig,

    'default': DevelopmentConfig,
}


def get_env():
    """获取当前环境的env"""

    # 优先检测container 注入的APPENV环境变量，如果没有就做常规检查
    env = os.getenv('APPENV')
    if not env:
        env = os.getenv('FLASK_ENV') or 'default'
    env = env.lower()
    return env


configure = config.get(get_env())
